﻿using System;
using System.Configuration;
using Citi.PTSConsolidation.Domain;
using Citi.PTSConsolidation.Domain.Utils;
using System.IO;
using System.Threading;
using System.Text;
using Citi.RoutineBase;
using ClosedXML.Excel;
using System.Data;
using System.Collections.Generic;
using Citi.PTSConsolidation.SchedulerUI;

namespace Citi.PTSConsolidation.ConsoleUI.EntrepotExtraction
{
    public class CurrentAction : ICurrentAction
    {
        public string Description
        {
            set { Console.WriteLine(value); }
        }

        public void StartLog(string message)
        {

        }

        public void StartLogOnFile(string filePath)
        {

        }

        public void StopLog()
        {

        }

        public void StopLogOnFile()
        {

        }
    }

    public class Program
    {
        //static string PtsConnectionString { get { return ConfigurationManager.AppSettings["PtsConnectionString"]; } }
        //static string EntrepotConnectionString { get { return ConfigurationManager.AppSettings["EntrepotConnectionString"]; } }
        //static string ErrorFile { get { return ConfigurationManager.AppSettings["ErrorFile"]; } }
        //static string FinishFile { get { return ConfigurationManager.AppSettings["FinishFile"]; } }

        public static void Main(string[] args)
        {
            var parameters = new Dictionary<string, object> { 
                { "RobotUsername", @"lac\lac_bra_ftools" }, { "RobotPassword", "Ferrari3k10" }
                , {"ApplicationPath",@"notepad"}
                //, {"LogApplicationPath",@"\\gruvnascti0016.wlb.lac.nsroot.net\DATA_GRP1\FTOOLS\Config\Encrypt\pearl-crc.pwd"}
                , {"ApplicationArguments",@"-blabla fulano"}
                //, {"ValidateFile",@"\\gruvnascti0016.wlb.lac.nsroot.net\DATA_GRP1\FTOOLS\Config\Encrypt\pearl-crc.pwd"}
                , {"UnlockLockMachine",@"true"}
                , {"Months", "09,10,11"}
                , {"Year", 2014}
                , {"EmailUsers", "nd61955"}, {"BZTEPrograms", "true"}
            };

            ICurrentAction action = new CurrentAction();
            new SchedulerUI.TimeBookingImport().Start(DateTime.Now, ref action, parameters);
            //new SchedulerUI.ApplicationExtractionCurrentYear().Start(DateTime.Now, ref action, parameters);
            //new SchedulerUI.ClientAllocationExtractionNextYear().Start(DateTime.Now, ref action, parameters);

//            new SchedulerUI.ApplicationPercentageExtraction().Start(DateTime.Now, ref action, parameters);
//new SchedulerUI.SystemMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-0), ref action, parameters);

            //new SchedulerUI.ApplicationCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-0), ref action, parameters);
//            new SchedulerUI.FinancialTypeExtraction().Start(DateTime.Today.AddDays(-0), ref action, parameters);
            //new SchedulerUI.ClientJustificationMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-0), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-0), ref action, parameters);
            //new SchedulerUI.ApplicationDetailExtraction().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.ApplicationCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);
            //new Scheduler.RunnerApplication.SchedulerUI.Execution().Start(DateTime.Now, ref action, parameters);
            //new ClientAllocationExtractionCurrentYear().Start(DateTime.Today, ref action, parameters);

            //new SchedulerUI.SystemMonthlyVarianceNextYearReportGeneration().Start(DateTime.Today, ref action, parameters);

            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-6), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-5), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-4), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-3), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-1), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(0), ref action, parameters);
            //new SchedulerUI.SystemMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(0), ref action, parameters);

            //new SchedulerUI.ApplicationCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.LagCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);

            //new SchedulerUI.ApplicationExtractionCurrentYear().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-4), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-3), ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);

            //return;
            //new SchedulerUI.SystemMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-2), ref action, parameters);
            //new SchedulerUI.SystemMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-1), ref action, parameters);
            //new SchedulerUI.SystemMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.ClientMonthlyVarianceCurrentYearReportGeneration().Start(DateTime.Today.AddDays(-0), ref action, parameters);
            //new SchedulerUI.EntrepotExtractionNextYear().Start(DateTime.Today.AddDays(0), ref action, parameters);
            //new SchedulerUI.ClientAllocationExtractionCurrentYear().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.LagCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.GocExtraction().Start(DateTime.Today.AddDays(0), ref action, parameters);
            //new Scheduler.RunnerApplication.SchedulerUI.RefreshPivotTables().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.ClientAllocationExtractionCurrentYear().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.ClientDailyVarianceCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.LagPreviousYearReportGeneration().Start(DateTime.Today.AddDays(0), ref action, parameters);
            //new SchedulerUI.LagCurrentYearReportGeneration().Start(DateTime.Today.AddDays(0), ref action, parameters);
            //new SchedulerUI.LagCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.LagNextYearReportGeneration().Start(DateTime.Today.AddDays(0), ref action, parameters);
            //new SchedulerUI.ApplicationExtraction().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.PTSPreviousYearReportGeneration().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.ApplicationExtractionCurrentYear().Start(DateTime.Today, ref action, parameters);
            //new SchedulerUI.ApplicationCurrentYearReportGeneration().Start(DateTime.Today, ref action, parameters);


            //try
            //{
            //    Console.WriteLine("Table PTS Entrepot to Extract: {0}", args[0]);

            //    Console.WriteLine("Entrepot Year {0}: Copy has started at {1}", args[1], DateTime.Now);
            //    var query = BookOfWork.GetEntrepotQueryString(args[0]);
            //    SqlHelper.CopyDataFromAnotherDatabase(EntrepotConnectionString, query, string.Concat("BookOfWork", args[1]),
            //            PtsConnectionString, BookOfWork.BookOfWorkColumnMappings);
            //    Console.WriteLine("Entrepot Year {0}: Copy has finished at {1}", args[1], DateTime.Now);

            //    File.CreateText(string.Format(FinishFile, args[1]));
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e.ToString());
            //    File.WriteAllText(ErrorFile, e.ToString());
            //    throw e;
            //}

            Console.WriteLine("Press any key to close...");
            Console.ReadKey();
        }
    }
}